package com.situ.blog.controller;

import com.situ.blog.pojo.Blog;
import com.situ.blog.util.JSONUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/blog")
public class BlogController extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Blog blog1 = new Blog();
        blog1.setId(1);
        blog1.setName("Java学习");
        Blog blog2 = new Blog();
        blog2.setId(2);
        blog2.setName("UI学习");
        List<Blog> list = new ArrayList<>();
        list.add(blog1);
        list.add(blog2);

        JSONUtil.toJSON(resp, list);
    }
}
